<?php

namespace app\admin\model\promotion;

use think\Model;
use traits\model\SoftDelete;

class Setup extends Model
{

    use SoftDelete;

    

    // 表名
    protected $name = 'promotion_set';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = 'deletetime';

    // 追加属性
    protected $append = [
        'threshold_text',
        'atype_text',
        'oktype_text',
        'customer_text',
        'purchase_text',
        'stype_text',
        'balance_text',
        'ctype_text',
        'dtype_text',
        'itype_text',
        'status_text'
    ];
    

    
    public function getThresholdList()
    {
        return ['0' => __('Threshold 0'), '1' => __('Threshold 1'), '2' => __('Threshold 2')];
    }

    public function getAtypeList()
    {
        return ['0' => __('Atype 0'), '1' => __('Atype 1')];
    }

    public function getOktypeList()
    {
        return ['0' => __('Oktype 0'), '1' => __('Oktype 1')];
    }

    public function getCustomerList()
    {
        return ['0' => __('Customer 0'), '1' => __('Customer 1'), '2' => __('Customer 2')];
    }

    public function getPurchaseList()
    {
        return ['0' => __('Purchase 0'), '1' => __('Purchase 1')];
    }

    public function getStypeList()
    {
        return ['0' => __('Stype 0'), '1' => __('Stype 1')];
    }

    public function getBalanceList()
    {
        return ['0' => __('Balance 0'), '1' => __('Balance 1'), '2' => __('Balance 2')];
    }

    public function getCtypeList()
    {
        return ['0' => __('Ctype 0'), '1' => __('Ctype 1')];
    }

    public function getDtypeList()
    {
        return ['0' => __('Dtype 0'), '1' => __('Dtype 1')];
    }

    public function getItypeList()
    {
        return ['0' => __('Itype 0'), '1' => __('Itype 1'), '2' => __('Itype 2'), '3' => __('Itype 3')];
    }

    public function getStatusList()
    {
        return ['0' => __('Status 0'), '1' => __('Status 1')];
    }


    public function getThresholdTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['threshold']) ? $data['threshold'] : '');
        $list = $this->getThresholdList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getAtypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['atype']) ? $data['atype'] : '');
        $list = $this->getAtypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getOktypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['oktype']) ? $data['oktype'] : '');
        $list = $this->getOktypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCustomerTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['customer']) ? $data['customer'] : '');
        $list = $this->getCustomerList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getPurchaseTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['purchase']) ? $data['purchase'] : '');
        $list = $this->getPurchaseList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['stype']) ? $data['stype'] : '');
        $list = $this->getStypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getBalanceTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['balance']) ? $data['balance'] : '');
        $list = $this->getBalanceList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getCtypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['ctype']) ? $data['ctype'] : '');
        $list = $this->getCtypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getDtypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['dtype']) ? $data['dtype'] : '');
        $list = $this->getDtypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getItypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['itype']) ? $data['itype'] : '');
        $list = $this->getItypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
        $list = $this->getStatusList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function shop()
    {
        return $this->belongsTo('app\admin\model\wanlshop\Shop', 'shop_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
